////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2010 Gabriel Montagné Láscaris-Comneno and Alberto
//  Brealey-Guzmán.
//
//  Permission is hereby granted, free of charge, to any person obtaining a
//  copy of this software and associated documentation files (the "Software"),
//  to deal in the Software without restriction, including without limitation
//  the rights to use, copy, modify, merge, publish, distribute, sublicense,
//  and/or sell copies of the Software, and to permit persons to whom the
//  Software is furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
//  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
//  DEALINGS IN THE SOFTWARE.
//
////////////////////////////////////////////////////////////////////////////////

package com.rojored.core
{

/**
 *  Contract for cache implmementations.
 *
 *  <p>Roughly modelled after the memcache API as implemented in Python for
 *  the GAE</p>
 *
 *  @see http://code.google.com/appengine/docs/python/memcache/functions.html
 */
public interface ICache
{

    //--------------------------------------------------------------------------
    //
    //  Methods
    //
    //--------------------------------------------------------------------------

    /**
     *  Set a key's value, regardless of previous contents in cache.
     *
     *  @param Key to set.
     *  @param Value to set.
     *  @param Optional expiration time.
     *  @return True if set, false on error.
     */
    function set(key:*, value:*, time:int = 0):Boolean;

    /**
     *  Sets a key's value, if and only if the item is not already in
     *  cache.
     *
     *  @param Key to set.
     *  @param Value to set.
     *  @param Optional expiration time.
     *  @return True if added, false on error.
     */
    function add(key:*, value:*, time:int = 0):Boolean;

    /**
     *  Replaces a key's value, failing if item isn't already in cache.
     *
     *  @param Key to set.
     *  @param Value to set.
     *  @param Optional expiration time.
     *  @return True if replaced. False on error or cache miss.
     */
    function replace(key:*, value:*, time:int = 0):Boolean;

    /**
     *  Look up a key in cache.
     *
     *  @param Key of value to retrieve.
     *  @return The value of the key, if found in cache, else undefined.
     */
    function get(key:*):*;

    /**
     *  Delete everything in cache.
     *
     *  @return True on success, false on error.
     */
    function flushAll():Boolean;

    /**
     *  Remove an item from the cache.
     *
     *  @param Key to delete.
     *  @param Optional number of seconds to make deleted items 'locked' for
     *  'add' operations.
     *  @return 0 (DeleteStatus.DELETE_FAILURE) on failure,
     *  1 (DeleteStatus.DELETE_ITEM_MISSING) if the item to be deleted wasn't
     *  there, or 2 (DeleteStatus.DELETE_SUCCESSFUL) if the item was actually
     *  deleted.  This can be used as a boolean value where failure is the
     *  only bad condition.
     *
     *  @see com.rojored.core.cacheClasses.DeleteStatus
     */
    function deleteItem(key:*, seconds:int = 0):int;
}
}
